package mysql;

import com.mysql.cj.jdbc.Driver;
import com.wxy.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

class usermessage{
    String name;
    String pwd;
    public usermessage(){}
    public usermessage(String name, String pwd) {
        this.name = name;
        this.pwd = pwd;
    }
    @Override
    public String toString(){
        return name+pwd;
    }
}

class connection{
    public static Connection getConnection(){
        Connection conn;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            DriverManager.registerDriver(new Driver());
            conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/wxy","root","13579");
            return conn;
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return null;
    }
}
/**
 * @author 47868
 */
public class DbutilsTest {
    public static void main(String[] args) throws SQLException {
        QueryRunner runner = new QueryRunner();
        List<usermessage> users = runner.query(connection.getConnection(),"select * from user", new BeanListHandler<>(usermessage.class));
        for (usermessage user : users) {
            System.out.println(user);
        }
    }
}
